/***************************init***************/

function queryAlbum_photo(){
	sys_loading();
	var parm = $('#queryAlbumForm').serialize();
	var url = create_url('photo-query');
	sys_record_parm('photo',parm);
	$.ajax({type:'POST', url:url, data:parm,
		success: function(result) {
			sys_loading_close();
			$('#albumResultList').html(result);
		}
	});
}

function editAlbum_photo(code) {
	var parm = {'code':code};
	var url = create_url("photo-editAlbum");
	sys_record_parm('photo',parm);
	$.colorbox({overlayClose:false, href:url, data:parm, close:'[关闭]', width:'350px', open:true});
}


function showPhoto_photo(code) {
	var parm = {'code':code};
	var url = create_url("photo-photoShow");
	$.colorbox({overlayClose:false, href:url, data:parm, close:'[关闭]', width:'1000px', open:true});
}


function queryPhoto_photo(alc){
	var parm = {'alc':alc};
	var url = create_url('photo-queryPhoto');
	$.ajax({type:'POST', url:url, data:parm,
		success: function(result) {
			sys_loading_close();
			$('#albumResultList').html(result);
		}
	});
}


function deleteAlbum_photo(code){
	sys_loading();
	var parm = {'code':code};
	var url = create_url('photo-deleteAlbum');
	$.ajax({type:'POST', url:url, data:parm,
		success: function(result) {
			sys_submiting_close();
			if (result == 'success') {
				sys_msg('操作成功');
				queryAlbum_photo();
				
			} else {
				sys_msg('操作失败', '警告');
			}
		}
	});
}

function deletePhoto_photo(code){
	sys_loading();
	var parm = {'code':code};
	var alc = $('#alc').val()
	var url = create_url('photo-delete');
	$.ajax({type:'POST', url:url, data:parm,
		success: function(result) {
			sys_submiting_close();
			if (result == 'success') {
				sys_msg('操作成功');
				queryPhoto_photo(alc);
				
			} else {
				sys_msg('操作失败', '警告');
			}
		}
	});
}


function addFilesUploadEvent_photo() {
	var alc = $('#alc').val()
	var url = create_url('photo-uploads' + "_" + $('#alc').val());
	var btn = $('#uploadFilesBtn');
	new AjaxUpload(btn, {
		action:url,
		name:'files',
		multiple: true,
		responseType: 'json',
		onSubmit : function(file, ext) {
			if (ext && /^(|jpg|png|gif|bmp|JPG|PNG|GIF|BMP)$/.test(ext)){
				this.setData({
					'info':'文件类型正确'
				});
			} else {
				sys_msg('文件类型错误', '只能上传类型为：JPG,PNG,BMP图片文件!');
				return false;               
			}
			$('#uploads_span').html(sys_loading_img);
			this.disable();
		},
		onComplete: function(files, response){
			if ('error' == response.result)
				sys_msg('失败', '上传文件失败，请检查文件名是否正确!');
			else if ('file_type_error' == response.result)
				sys_msg('文件类型错误', '只能上传类型为：JGP、GIF、BMP、PNG的文件!');
			else {
				var index = parseInt($('#photo_index').val());
				this.enable();
				$('#document_index').val(index);
				queryPhoto_photo(alc);
			}
		}
	});
}

/**************************edit****************************/

function saveAlbum_photo() {
	var parm = $('#editAlbumForm').serialize();
	var url = create_url('photo-saveAlbum');
	sys_submiting();
	$.ajax({type:'POST', url:url, data:parm,
		success: function(result) {
			sys_submiting_close();
			if (result == 'success') {
				sys_msg('操作成功');
				queryAlbum_photo();
			} else {
				sys_msg('操作失败');
			}
		}
	});
}

function savep_photo() {
	var parm = $('#photoListForm').serialize();
	var url = create_url('photo-savep');
	sys_submiting();
	$.ajax({type:'POST', url:url, data:parm,
		success: function(result) {
			sys_submiting_close();
			if (result == 'success') {
				sys_msg('操作成功');
				queryAlbum_photo();
			} else if (result == 'exists') {
				sys_msg('还没有设置封面哦！');
			} else {
				sys_msg('操作失败', '警告');
			}
		}
	});
}
function check1_photo(obj){
	var checks =$('#photoListForm').find('input.box');
	if(obj.attr('checked') || 'checked' == obj.attr('checked')){
		checks.each(function(e) {
			$(this).removeAttr('checked');
		});
		obj.attr('checked',true);
	}
}